package com.command.center.pucms.pucmsgateway.controller;

import com.alibaba.fastjson.JSONObject;
import com.command.center.pucms.common.enums.CodeEnum;
import com.command.center.pucms.pucmsgateway.annotation.Pass;
import com.command.center.pucms.pucmsgateway.service.IUserService;
import com.command.platform.core.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 *  登录接口
 * @author zlb
 * @since 2021-04-23
 */
@RestController
@Api(tags="登录认证模块")
public class LoginController {

    @Autowired
    private IUserService userService;

    @ApiOperation(value = "登录操作，返回用户token信息，pass注解跳过认证", notes = "登录操作")
    @PostMapping("/login")
    @Pass
    public Result login(@RequestBody JSONObject requestJson) throws Exception{

        Map<String, Object> stringObjectMap = userService.checkUserNameAndPasswd(requestJson);
        return Result.success(CodeEnum.SUCCESS.getMsg(),stringObjectMap);
    }


    /**
     * 登出
     * @return
     */
    @ApiOperation(value = "登出操作", notes = "登录操作")
    @GetMapping(value = "/logout")
    @Pass
    public Result logout(){
        userService.logout();
        return Result.success(CodeEnum.SUCCESS.getMsg(),null);
    }




}
